function UserAdd_Code(id){
	var date=new Date().Format("yyyy-MM-dd");
	var buffer = new StringBuffer();
	buffer.append('<div id="userid" val="'+id+'" class="crmsheet border-bottom"><div class="ctitle"><div class="cname">账号</div><div class="require">*</div></div><div class="ctext"><input id="txt_username" type="tel" maxlength="11" placeholder="必须为手机号" value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">密码</div><div class="require">*</div></div><div class="ctext"><input id="txt_userpwd" type="text" placeholder="填写密码（6-18位）" value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">姓名</div><div class="require">*</div></div><div class="ctext"><input id="txt_realname" type="text" placeholder="填写姓名" value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">性别</div><div class="require">*</div></div><div class="ctext"><div class="sex"><input id="boy" name="sex" type="radio" style="width:16px;" checked="checked" value="男"/><label for="boy">男</label></div><div class="sex"><input id="girls" name="sex" type="radio" style="width:16px;" value="女"/><label for="girls">女</label></div></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">部门</div><div class="require">*</div></div><div class="ctext"><select id="txt_departid"></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">职位</div><div class="require">*</div></div><div class="ctext"><select id="txt_roleid"></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">试用工资</div></div><div class="ctext"><input id="txt_asalary" type="tel" placeholder="填写试用期工资" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">转正工资</div></div><div class="ctext"><input id="txt_bsalary" type="tel" placeholder="填写转正后工资" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">试用期</div></div><div class="ctext"><input id="txt_adate" type="text" placeholder="选择试用期开始时间" value="'+date+'" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname"></div></div><div class="ctext"><input id="txt_bdate" type="text" placeholder="选择试用期结束时间" value="'+GetMonthStr(3).ToDate()+'" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">银行账号</div></div><div class="ctext"><input id="txt_banknum" type="tel" placeholder="填写银行账号" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">开户银行</div></div><div class="ctext" style="width:55%;"><input id="txt_bankname" type="text" placeholder="填写开户银行" value="" onfocus="ScrollTop()"/></div><div id="bankselect" class="xuan lightblue">选</div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">入职时间</div></div><div class="ctext"><input id="txt_joindate" type="text" placeholder="选择入职时间" value="'+date+'" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">生日</div></div><div class="ctext"><input id="txt_birthday" type="text" placeholder="选择生日" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">电话</div></div><div class="ctext"><input id="txt_tel" type="tel" placeholder="填写电话" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">身份证</div></div><div class="ctext"><input id="txt_idcard" type="tel" placeholder="填写身份证" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">籍贯</div></div><div class="ctext"><input id="txt_birthplace" type="text" placeholder="填写籍贯" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">现住址</div></div><div class="ctext"><input id="txt_address" type="text" placeholder="填写现住址" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">邮箱</div></div><div class="ctext"><input id="txt_email" type="text" placeholder="填写邮箱" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">QQ</div></div><div class="ctext"><input id="txt_qq" type="tel" placeholder="填写QQ" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">毕业院校</div></div><div class="ctext"><input id="txt_school" type="text" placeholder="填写毕业院校" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">毕业时间</div></div><div class="ctext"><input id="txt_schooldate" type="text" placeholder="选择毕业时间" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">教育类型</div></div><div class="ctext"><input id="txt_schooltype" type="text" placeholder="填写教育类型" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">专业</div></div><div class="ctext"><input id="txt_profession" type="text" placeholder="填写专业" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');

	return buffer.toString();
};


function Init_UserAdd(){
	var uid=$("#userid").attr("val");
	if(uid!=0)
	{
	    var data = {};
		data.act = "One_User";
		data.id=uid;
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		mui.getJSON(admin_domain, data, function (json) {
		    if (json.state) {
		    	var user=json.data;
		    	$("#txt_username").val(user.UserName);
		    	$("#txt_userpwd").val(user.UserPwd);
		        $("#txt_realname").val(user.RealName);
		        $("input[name='sex'][value='"+user.Sex+"']").prop("checked", true);
		        $("#txt_depart").val(user.DepartName);
		        $("#txt_duty").val(user.RoleName);
		        $("#txt_joindate").val(user.JoinDate.ToDate());
		        $("#txt_birthday").val(user.Birthday.ToDate());
		        $("#txt_tel").val(user.Tel);  
		        $("#txt_idcard").val(user.IDCard);
		        $("#txt_birthplace").val(user.BirthPlace);
		        $("#txt_address").val(user.Address);
		        $("#txt_email").val(user.Email);
		        $("#txt_qq").val(user.QQ);
		        $("#txt_school").val(user.School);
		        $("#txt_schooldate").val(user.SchoolDate.ToDate());
		        $("#txt_schooltype").val(user.SchoolType);
		        $("#txt_profession").val(user.Profession);
		        $("#txt_asalary").val(user.ASalary);
		        $("#txt_bsalary").val(user.BSalary);
		        $("#txt_adate").val(user.ADate.ToDate());
		        $("#txt_bdate").val(user.BDate.ToDate());
		        $("#txt_bankname").val(user.BankName);
		        $("#txt_banknum").val(user.BankNum);
		        $("#txt_profession").val(user.Profession);
		        $("#txt_profession").val(user.Profession);
		    	Init_DepartAndRole(user.DepartID,user.RoleID);
		    }
		});
	}else
	{ 
		Init_DepartAndRole(0,0);
	}
	
	
	mui(".divmsg").on("tap",".date",function(){
			obj10=this;
			var t=new Date();
			if($(this).find("input").val()!="")
			{
				var year_month_day=$(this).find("input").val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj10).find("input").val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
		});
		get("bankselect").addEventListener("tap",function(){
			OpenWindow(4,"选择银行","",function(){});
			$("#contentlist4").html(BankSelect_Code());
			Init_BankSelect();
		});
};

function Init_DepartAndRole(departid,roleid){
	var data = {};
		data.act = "DepartAndRole_Data";
		data.id=userid;
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		mui.getJSON(admin_domain, data, function (json) {
		    if (json.state) {
		    	var departlist=json.data.departlist;
		    	var rolelist=json.data.rolelist;
		    	var str1='',str2='';
		    	var isselect1='',isselect2='';
		    	if(departlist.length>0)
		    	{
		    		str1='<option value="'+departlist[0].topdepart.ID+'">'+departlist[0].topdepart.Name+'</option>';
		    	}
		    	$.each(departlist,function(i,info){
		    		if (info.big.ID == departid)
                    {
                        isselect1 = "selected='selected'";
                    }
                    else {
                        isselect1 = "";
                    } 
		    		str1+='<option value="'+info.big.ID+'" '+isselect1+'>'+info.big.Name+'</option>';
		    		$.each(info.small,function(k,small){
		    		if (small.ID == departid)
                    {
                        isselect1 = "selected='selected'";
                    }
                    else {
                        isselect1 = "";
                    } 
		    		str1+='<option value="'+small.ID+'" '+isselect1+'>'+small.Name+'</option>';
		    		});
		    	});
		    	$("#txt_departid").html(str1);
		    	
		    	
		    	$.each(rolelist,function(i,info){
		    		if (info.ID == roleid)
                    {
                        isselect2 = "selected='selected'";
                    }
                    else {
                        isselect2 = "";
                    } 
		    		str2+='<option value="'+info.ID+'" '+isselect2+'>'+info.Name+'</option>';
		    	});
		    	$("#txt_roleid").html(str2);
		    }
		});
};


function Save_User() {
        var data = {};
        var txt_username = $("#txt_username");
        var txt_userpwd = $("#txt_userpwd");
        var txt_realname = $("#txt_realname");
        var sex = $("input[name='sex']:checked");
        var txt_departid = $("#txt_departid");
        var txt_roleid = $("#txt_roleid");
        data.id = $("#userid").attr("val");
        if(txt_username.val().Trim()=="")
        {
        	plus.nativeUI.toast("请填写账号（手机号码）");
        	return false;
        }
        if(txt_username.val().Trim().length!=11)
	    {
	        plus.nativeUI.toast("账号（手机号码）必须为11位数字");
	        return;
	    }
        if(txt_userpwd.val().Trim()=="")
        {
        	plus.nativeUI.toast("请填写密码");
        	return false;
        }
        if (txt_userpwd.val().length < 6 || txt_userpwd.val().length > 18) {
	        plus.nativeUI.toast("密码长度必须在6-18位之间");
	        return;
        }
        if(txt_realname.val().Trim()=="")
        {
        	plus.nativeUI.toast("请填写真实姓名");
        	return false;
        }
		data.act = "Save_User";
		data.username = txt_username.val();
        data.userpwd = txt_userpwd.val();
        data.realname = txt_realname.val();
        data.sex = sex.val();
        data.departid = txt_departid.val();
        data.roleid = txt_roleid.val();
        data.asalary=$("#txt_asalary").val();
        data.bsalary=$("#txt_bsalary").val();
        data.adate=$("#txt_adate").val();
        data.bdate=$("#txt_bdate").val();
        data.banknum=$("#txt_banknum").val();
        data.bankname=$("#txt_bankname").val();
        data.joindate = $("#txt_joindate").val();
        data.birthday = $("#txt_birthday").val();
        data.tel = $("#txt_tel").val();
        data.idcard = $("#txt_idcard").val();
        data.birthplace = $("#txt_birthplace").val();
        data.address = $("#txt_address").val();
        data.email = $("#txt_email").val();
        data.qq = $("#txt_qq").val();
        data.school = $("#txt_school").val();
        data.schooldate = $("#txt_schooldate").val();
        data.schooltype = $("#txt_schooltype").val();
        data.profession = $("#txt_profession").val();
        data.userid=userid;
		data.comid=comid;
        data.source = source; 
        data.version = version;
        data.sign=GetSign(data.act);
        mui.getJSON(admin_domain, data, function (json) {
            if (json.state) {
                CloseWindow();
                plus.nativeUI.toast(json.msg); 
                if(data.id==0)
                {
                	Receive_User(1);
                }else{
                	Init_UserDetail();
                	obj.find(".realname").html(data.realname+"<font>"+data.username+"</font>");
                	obj.find(".birthplace").html(data.birthplace);
                	if(data.birthday!="")
                	{
                		obj.find(".sex").html(data.sex+'&nbsp;('+DateDiff("Y", data.birthday, now+'')+'岁)');
                	}
                	obj.find(".joindate").html('入职时间：'+data.joindate);
                }
            } else {
				plus.nativeUI.toast(json.msg);
            }
        });
};

function BankSelect_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/gongshang.jpg"/></div><div class="bankname">中国工商银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/jianshe.jpg"/></div><div class="bankname">中国建设银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/nongye.jpg"/></div><div class="bankname">中国农业银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/jiaotong.jpg"/></div><div class="bankname">交通银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/zhaoshang.jpg"/></div><div class="bankname">招商银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/guangda.jpg"/></div><div class="bankname">中国广大银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/zhongguo.jpg"/></div><div class="bankname">中国银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/zhongxin.jpg"/></div><div class="bankname">中信银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/minsheng.jpg"/></div><div class="bankname">中国民生银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/pufa.jpg"/></div><div class="bankname">浦发银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/guangfa.jpg"/></div><div class="bankname">广发银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/huaxia.jpg"/></div><div class="bankname">华夏银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/xingye.jpg"/></div><div class="bankname">兴业银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/pingan.jpg"/></div><div class="bankname">平安银行</div></div>');
	buffer.append('<div class="banklist border-bottom"><div class="banklogo"><img src="img/youzheng.jpg"/></div><div class="bankname">中国邮政</div></div>');
	
	return buffer.toString();
};

function Init_BankSelect()
{
	mui("#contentlist4").off("tap",".banklist");
	mui("#contentlist4").on("tap",".banklist",function(){
		$("#txt_bankname").val($(this).find(".bankname").html());
		CloseWindow();
	});
};
